package com.xzq.erp.utils;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;

public class KeyGeneratorExample {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        // 使用 HMAC-SHA256 算法生成密钥
        KeyGenerator kg = KeyGenerator.getInstance("HmacSHA256");
        SecretKey secretKey = kg.generateKey();
        
        // 将密钥转换为 Base64 编码的字符串
        String encodedKey = java.util.Base64.getEncoder().encodeToString(secretKey.getEncoded());
        System.out.println("生成的密钥: " + encodedKey);
    }
}